/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.model.inventory;

import com.xtd.model.employment.Employee;
import com.xtd.model.retail.OrderCommodity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Lu Yuanbin
 */
@Entity
@Table(name = "inventory_record")
@NamedQueries({
    @NamedQuery(name = "InventoryRecord.findAll", query = "SELECT i FROM InventoryRecord i")})
public class InventoryRecord implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "stock_type")
    private boolean stockType;
    @Column(name = "quantity")
    private Integer quantity;
    @Column(name = "createdTime")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdTime;
    @Column(name = "cancelled")
    private boolean cancelled;
    @JoinColumn(name = "createdBy", referencedColumnName = "id")
    @ManyToOne
    private Employee createdBy;
    @JoinColumn(name = "commodity", referencedColumnName = "id")
    @ManyToOne
    private Commodity commodity;
    @JoinColumn(name = "order_commodity", referencedColumnName = "id", insertable = true, updatable = true)
    @ManyToOne
    private OrderCommodity orderCommodity;
    @JoinColumn(name = "purchase_record", referencedColumnName = "id")
    @ManyToOne
    private PurchaseRecord purchaseRecord;

    public InventoryRecord() {
    }

    public InventoryRecord(OrderCommodity orderCommodity, boolean stockType, Employee createdBy) {
        this.orderCommodity = orderCommodity;
        this.commodity = orderCommodity.getCommodity();
        this.stockType = stockType;
        this.createdTime = new Date();
        this.createdBy = createdBy;
    }

    public InventoryRecord(PurchaseRecord purchaseRecord, boolean stockType, Employee createdBy) {
        this.purchaseRecord = purchaseRecord;
        this.commodity = purchaseRecord.getCommodity();
        this.stockType = stockType;
        this.createdTime = new Date();
        this.createdBy = createdBy;
    }

    public InventoryRecord(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public boolean getStockType() {
        return stockType;
    }

    public void setStockType(boolean stockType) {
        this.stockType = stockType;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof InventoryRecord)) {
            return false;
        }
        InventoryRecord other = (InventoryRecord) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.xtd.model.inventory.InventoryRecord[id=" + id + "]";
    }

    /**
     * @return the commodity
     */
    public Commodity getCommodity() {
        return commodity;
    }

    /**
     * @param commodity the commodity to set
     */
    public void setCommodity(Commodity commodity) {
        this.commodity = commodity;
    }

    /**
     * @return the purchaseRecord
     */
    public PurchaseRecord getPurchaseRecord() {
        return purchaseRecord;
    }

    /**
     * @param purchaseRecord the purchaseRecord to set
     */
    public void setPurchaseRecord(PurchaseRecord purchaseRecord) {
        this.purchaseRecord = purchaseRecord;
    }

    /**
     * @return the orderCommodity
     */
    public OrderCommodity getOrderCommodity() {
        return orderCommodity;
    }

    /**
     * @param orderCommodity the orderCommodity to set
     */
    public void setOrderCommodity(OrderCommodity orderCommodity) {
        this.orderCommodity = orderCommodity;
    }

    /**
     * @return the createdTime
     */
    public Date getCreatedTime() {
        return createdTime;
    }

    /**
     * @param createdTime the createdTime to set
     */
    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    /**
     * @return the createdBy
     */
    public Employee getCreatedBy() {
        return createdBy;
    }

    /**
     * @param createdBy the createdBy to set
     */
    public void setCreatedBy(Employee createdBy) {
        this.createdBy = createdBy;
    }

    /**
     * @return the cancelled
     */
    public boolean isCancelled() {
        return cancelled;
    }

    /**
     * @param cancelled the cancelled to set
     */
    public void setCancelled(boolean cancelled) {
        this.cancelled = cancelled;
    }
}
